package ManagerRouter

import (
	"deepgox-go-admin/Middlewares"
	"deepgox-go-admin/Service/Rmq"
	"github.com/gin-gonic/gin"

	EsManagerService "deepgox-go-admin/Service/EsManager"
	ManagerService "deepgox-go-admin/Service/Manager"
)

func ManagerRouter(g *gin.RouterGroup) {
	// 配置 Hystrix 中间件
	hystrixConfig := Middlewares.HystrixConfig{
		CommandName:    "userService",
		Timeout:        1000, // 1秒超时
		MaxConcurrency: 50,   // 最大50个并发请求
		ErrorThreshold: 25,   // 错误率超过25%时熔断
		FallbackResponse: gin.H{ // 默认降级响应
			"code":    503,
			"message": "Service unavailable, please try again later",
		},
	}
	managerGroup := g.Group("/manager")
	//执行Hystrix
	managerGroup.POST("/login", Middlewares.HystrixMiddleware(hystrixConfig), ManagerService.LoginHandle)
	managerGroup.GET("/checkcode", ManagerService.CheckCode)
	//增加拦截器
	managerGroup.POST("/addmanager", Middlewares.JWTAuthMiddleware(), ManagerService.AddManager)
	managerGroup.POST("/byides", EsManagerService.ByIdEsManagerHandle)
	managerGroup.POST("/getesmanagerinfo", EsManagerService.ByIdEsManagerDataHandle)
	managerGroup.POST("/rmqaddmanager", Rmq.RmqAddManager)
}
